using System;
using System.Data;
using System.Data.Common;
using System.Data.OleDb;

namespace System.Data.DBLib
{
    /// <summary>
	/// Summary description for COleDB.
	/// </summary>
	public class COleDB : CDBLib
    {
        #region Constructor
        public COleDB()
		{
			//
			// TODO: Add constructor logic here
			//
        }
        #endregion

        #region Parameter
        public override DbParameter addParameter(string strFieldName, int nSize, int nType)
        {
            if (nType == 1)
            {
                return ((OleDbCommand)m_objCommand).Parameters.Add("@" + strFieldName, getType(nType), nSize);
            }
            else
            {
                return ((OleDbCommand)m_objCommand).Parameters.Add("@" + strFieldName, getType(nType));
            }
        }
        #endregion

        #region Function
        public override DbConnection getConnection()
        {
            m_strConnection = "Provider=SQLOLEDB.1;server=" + m_strServer + ";uid=" + m_strUserID + ";pwd=" + m_strPwd + ";database=" + m_strDatabase;
            return getConnection(m_strConnection);
        }

        public override DbConnection getConnection(string strConnection)
        {
            return new OleDbConnection(m_strConnection);
        }

        public override DbCommand getCommand(string strSql)
        {
            return new OleDbCommand(strSql, (OleDbConnection)m_objConnection);
        }

        public override DbDataAdapter getAdapter(string strSql)
        {
            OleDbDataAdapter da = new OleDbDataAdapter();
            da.SelectCommand = (OleDbCommand)getCommand(strSql);

            return da;
        }

        public override DbDataAdapter getAdapter()
        {
            OleDbDataAdapter da = new OleDbDataAdapter();
            da.SelectCommand = (OleDbCommand)m_objCommand;

            return da;
        }

        private OleDbType getType(int nType)
		{
			switch (nType)
			{
				case 0:
					return OleDbType.Integer;
				case 1:
					return OleDbType.VarChar;
				case 2:
					return OleDbType.Double;
				case 3:
					return OleDbType.VarWChar;
				case 4:
					return OleDbType.DBDate;
				case 5:
					return OleDbType.BigInt;
				case 6:
					return OleDbType.Decimal;
                case 7:
                    return OleDbType.LongVarBinary;
                case 8:
                    return OleDbType.BSTR;
                default:
                    return OleDbType.VarChar;
			}
		}
        #endregion

        public void addParameter(string p, object p_2)
        {
            throw new NotImplementedException();
        }
    }
}